<template>
  <div class="yarn-box">
    <div class="yarn-title">YARN队列</div>
    <div class="yarn-cont">
      <div class="yarn-tab">
        <span>队列名称</span>
        <span>占用百分比</span>
      </div>
      <div>
        <el-tree :data="yarnData" node-key="id" :props="defaultProps" @node-click="handleNodeClick">
          <span class="tree-cont" slot-scope="{ node, data }">
            <span class="tree-label">{{ data.queueName }}</span>
            <el-progress class="tree-progress" :stroke-width="18" :percentage="Number(data.capacity)"></el-progress>
          </span>
        </el-tree>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "YarnList",
  props: {
    yarnInfo: {
      type: Object,
      default: {}
    }
  },
  data() {
    return {
      yarnData: [],
      defaultProps: {
        children: "queue",
        label: "queueName"
      }
    };
  },
  watch: {
    // 监听yarnInfo值是否传到
    yarnInfo: {
      handler() {
        this.yarnData = this.yarnInfo.yarnInfo;
      }
    },
    deep: true
  },
  methods: {
    handleNodeClick(data) {
      console.log(data);
    }
  },
};
</script>

<style lang="scss" scoped>
.yarn-box {
  min-width: 49%;
  max-width: 50%;
  height: 400px;
  background: #fff;
  border-radius: 4px;
  overflow: hidden;
}
.yarn-title {
  width: calc(100% - 20px);
  height: 30px;
  font-size: 14px;
  line-height: 32px;
  padding-left: 20px;
  margin: 10px 10px 0 10px;
  border-radius: 4px 4px 0 0;
  background: #e4e7ed;
}
.yarn-cont {
  width: calc(100% - 20px);
  height: calc(100% - 50px);
  margin: 0 10px 10px 10px;
  border: 1px solid #dcdfe6;
  border-radius: 0 0 4px 4px;
  overflow-y: auto;
  .yarn-tab {
    width: 98%;
    background: #e4e7ed;
    font-size: 14px;
    padding: 4px;
    margin: 4px auto 0;
    display: flex;
    flex-flow: row nowrap;
    justify-content: flex-start;
    align-items: center;
    span {
      text-align: center;
    }
    span:nth-child(1) {
      width: 30%;
    }
    span:nth-child(2) {
      width: 70%;
    }
  }
  .tree-cont {
    width: 100%;
    display: flex;
    flex-flow: row nowrap;
    align-items: center;
    .tree-label {
      width: 30%;
      padding-left: 5px;
    }
    .tree-progress {
      width: 65%;
    }
  }
}
</style>